Skip to content

Fix: required validation for multi-select ComboBox (#9788)#9792

Merged
devongovett merged 5 commits intoadobe:mainfrom
Nawaz-B-04:fix-combobox-multiselect-required
Mar 18, 2026
Merged

Fix: required validation for multi-select ComboBox (#9788)#9792
devongovett merged 5 commits intoadobe:mainfrom
Nawaz-B-04:fix-combobox-multiselect-required

Conversation

@Nawaz-B-04
Copy link
Contributor

Closes #9788

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change.
  • Filled out test instructions.
  • Updated documentation (not required for this fix).
  • Looked at the Accessibility Practices for this feature.

📝 Test Instructions:

  1. Create a form containing a ComboBox with selectionMode="multiple" and isRequired.
  2. Select one or more items.
  3. Submit the form.

Expected result:
Form submission succeeds when items are selected.

  1. Submit the form with no selections.

Expected result:
Form validation prevents submission due to required constraint.

🧢 Your Project:

Personal open source contribution.

@github-actions github-actions bot added the RAC label Mar 14, 2026
let validation = useFormValidationState({
...props,
value: useMemo(() => Array.isArray(displayValue) && displayValue.length === 0 ? null : ({inputValue, value: displayValue as any, selectedKey}), [inputValue, selectedKey, displayValue])
value: useMemo(() => ({inputValue, value: displayValue as any, selectedKey}), [inputValue, selectedKey, displayValue])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. If the value is empty, validate should not be called. This should be handled by isRequired.

);
let comboBoxProps = removeDataAttributes(props);
if (props.selectionMode === 'multiple') {
delete comboBoxProps.isRequired;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we handle this inside the useComboBox hook?

values = [null];
// For multiple mode, add required to the hidden input when no values selected
let required = props.selectionMode === 'multiple' && props.isRequired;
inputs = [<input key="empty" type="hidden" name={name} form={props.form} value="" required={required} />];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually prevent form submission? I thought type="hidden" did not support required. We may need to use a type="text" with display: none here.

@Nawaz-B-04
Copy link
Contributor Author

Nawaz-B-04 commented Mar 18, 2026 via email

@devongovett
Copy link
Member

Added a commit to fix the tests and simplify the approach a little. I realized that we don't track the validation state for these hidden inputs, so we weren't displaying the validation errors properly. Instead of doing that, we can instead simply mark the visible text field as required but only if no items are selected.

@devongovett
Copy link
Member

@Nawaz-B-04 you'll need to sign the CLA

@devongovett devongovett added this pull request to the merge queue Mar 18, 2026
Merged via the queue into adobe:main with commit 92aef13 Mar 18, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isRequired validation fails on multi-select ComboBox

5 participants